@include "oneliners.awk"
@include "o.awk"
@include "slurp.awk"
@include "tests.awk"
@include "args2opt.awk"

function misc( _local) { return 1 }

function f2s(f,n) { return sprintf("%" f "f",n) }
function trim(s) {
    sub(/^[ \t\r\n]*/,"",s)
    sub(/[ \t\r\n]*$/,"",s)
    return s
} 
function s2a(string,array,   _sep,    n,i,tmp) {
    n=split(string, tmp, the(_sep,","))
    for(i=1;i<n;i+= 2) 
        array[tmp[i]] = tmp[i+1]
}
function a2s(array,     _sep,  i,between,out) {
    _sep = the(_sep,",")
    for(i in array) {
        out     = out between i "=" array[i]
        between = _sep }
    return out
} 
function abs(x)  { return x < 0 ? -1*x : x}
#### the following are defined for positive n,x,y
function any(n)       { return rand()*n }
function anyi(n)      { return withini(0,n-1) }
function seed(x)      { srand(the(x,systime()+PROCINFO["pid"])) }
function within(x,y)  { return x + (y - x)*rand() }
function withini(x,y)  { return int(x + (y + 1 - x)*rand()) }

function sd(sq,sum,n) { 
    return sqrt((sq-((sum*sum)/n))/(n-1)) 
}
function a2sd(a,db,       i) {
    for(i in a) {
        db["n"]++
        db["sum"]   += a[i]
        db["sumSq"] += a[i]*a[i] }
}
